<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${packageName}.mapper.${mapperName}">

    <resultMap id="BaseResultMap" type="${packageName}.model.${modelName}">
        <#list columns as column>
            <<#if column.primary??>id<#else>result</#if> column="${column.columnName}" property="${column.propertyName?uncap_first}" jdbcType="<#if column.type='INT'>INTEGER<#elseif column.type='DATETIME'>TIMESTAMP<#elseif column.type='TEXT'>VARCHAR<#elseif column.type='TEXT'>VARCHAR<#elseif column.type='LONGTEXT'>LONGVARCHAR<#else>${column.type}</#if>" />
        </#list>
    </resultMap>

    <sql id="Base_Column_List">
        <#list columns as column>
            <#if column_index < columns?size -1>${column.columnName},<#else>${column.columnName}</#if>
        </#list>
    </sql>

    <select id="selectList" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from ${tableName}
        <where>
        <#list columns as column>
            <if test="${column.propertyName?uncap_first} != null">
                and ${column.columnName} = <#noparse>#{</#noparse>${column.propertyName?uncap_first},jdbcType=<#if column.type='INT'>INTEGER<#elseif column.type='DATETIME'>TIMESTAMP<#elseif column.type='LONGTEXT'>LONGVARCHAR<#else>${column.type}</#if>}
            </if>
        </#list>
        </where>
        order by id desc
    </select>

    <insert id="insertSelective" >
        insert into ${tableName}
        <trim prefix="(" suffix=")" suffixOverrides=",">
        <#list columns as column>
            <if test="${column.propertyName?uncap_first} != null">
                ${column.columnName},
            </if>
        </#list>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
        <#list columns as column>
            <if test="${column.propertyName?uncap_first} != null">
                <#noparse>#{</#noparse>${column.propertyName?uncap_first},jdbcType=<#if column.type='INT'>INTEGER<#elseif column.type='DATETIME'>TIMESTAMP<#elseif column.type='TEXT'>VARCHAR<#elseif column.type='LONGTEXT'>LONGVARCHAR<#else>${column.type}</#if>},
            </if>
        </#list>
        </trim>
    </insert>

    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from ${tableName}
        where id = <#noparse>#{id}</#noparse>
    </select>

    <update id="updateByPrimaryKeySelective">
        update ${tableName}
        <set>
        <#list columns as column>
            <if test="${column.propertyName?uncap_first} != null">
                ${column.columnName} = <#noparse>#{</#noparse>${column.propertyName?uncap_first},jdbcType=<#if column.type='INT'>INTEGER<#elseif column.type='DATETIME'>TIMESTAMP<#elseif column.type='TEXT'>VARCHAR<#elseif column.type='LONGTEXT'>LONGVARCHAR<#else>${column.type}</#if>},
            </if>
        </#list>
        </set>
        where id = <#noparse>#{id}</#noparse>
    </update>

    <delete id="deleteByIds">
        delete from ${tableName} where id in
    <#noparse>
        <foreach collection="list" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </#noparse>
    </delete>
</mapper>
